/*
package com.zhou.framework.elasticsearch;

import org.apache.http.Header;
import org.apache.http.HttpHost;
import org.apache.http.message.BasicHeader;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.Base64Utils;

import java.time.Duration;
import java.util.ArrayList;
import java.util.List;


*/
/**
    配置中文分词
          POST /common_ques/_doc/_mapping
         {
         "properties": {
         "searchBody": {
         "type": "text",
         "analyzer": "ik_max_word",
         "search_analyzer": "ik_smart"
         }
         }
         }
    验证中文分词是否配置
     GET /common_ques/_analyze
     {

     "text":"中华人民共和国MN",
     "tokenizer":"ik_max_word"
     }

 *//*

@Configuration
public class ElasticSearchConfig {

    @Value("${elasticsearch.host}")
    private String host;
    @Value("${elasticsearch.port}")
    private int port;
    @Value("${elasticsearch.username}")
    private String username;
    @Value("${elasticsearch.password}")
    private String password;


    @Bean
    public RestHighLevelClient restHighLevelClient() {
        HttpHost post = new HttpHost(host, port);
        */
/*final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));*//*

        RestClientBuilder builder = RestClient.builder(post);
        builder.setRequestConfigCallback(requestConfigBuilder -> {
            requestConfigBuilder.setConnectTimeout(-1);
            requestConfigBuilder.setSocketTimeout(-1);
            requestConfigBuilder.setConnectionRequestTimeout(-1);
            return requestConfigBuilder;
        });
        builder.setMaxRetryTimeoutMillis(5*60*1000);
        builder.setHttpClientConfigCallback(httpClientBuilder -> {
            httpClientBuilder.disableAuthCaching();
            //httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
            //最大连接数
            httpClientBuilder.setMaxConnTotal(10);
            List<Header> headerList = new ArrayList<>();
            String key = username+":"+password;
            String bt = "Basic "+ new String(Base64Utils.encode(key.getBytes()));
            BasicHeader header = new BasicHeader("Authorization",bt);
            headerList.add(header);
            httpClientBuilder.setDefaultHeaders(headerList);
            //最大路由连接数
            httpClientBuilder.setMaxConnPerRoute(10);
            //每五分钟检验http连接，防止连接断开
            httpClientBuilder.setKeepAliveStrategy((response,context)-> Duration.ofMinutes(5).toMillis());
            httpClientBuilder.disableAuthCaching();
            return httpClientBuilder;
        });
        RestHighLevelClient client = new RestHighLevelClient(builder);
        return client;
    }
}
*/
